export default {
    namespaced: true,
    state: {
        cartList: []
    },
    getters: {
        totalAmount(state) {
            return state.cartList.reduce((pre, cur) => {
                if (cur.checked) {
                    return pre + parseInt(cur.qty) * parseFloat(cur.price);
                } else {
                    return pre;
                }
            }, 0);
        },
        totalCount(state) {
            return state.cartList.filter((item) => item.checked).length;
        },
        checkAll(state) {
            return !state.cartList.some((item) => !item.checked);
        },
    },
    mutations: {
        cartList(state, data) {
            state.cartList = data;
        },
        updateCartList(state, checkStatus) {
            state.cartList.forEach(item => {
                item.checked = checkStatus
            });
        },
    },
    actions: {
    },
    modules: {
    }
}